/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * InschrijvingToernooi.java
 *
 * Created on Jan 9, 2012, 4:46:07 AM
 */
package view;

import javax.swing.JOptionPane;
import model.Toernooi;
import model.Speler;
import model.ToernooiInschrijving;
//
/**
 *
 * @author Roalnd
 */
public class ToernooiSpelerWijzigen extends javax.swing.JFrame {


    ToernooiInschrijving toernooiWijzigen;

    /** Creates new form InschrijvingToernooi */
    public ToernooiSpelerWijzigen() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        jLabel1 = new javax.swing.JLabel();
        searchField = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        toernooiField = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        spelerField = new javax.swing.JTextField();
        spelerBetaaldCheckbox = new javax.swing.JCheckBox();
        confirmButton = new javax.swing.JButton();
        searchButton = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setTitle("Toernooi spelerinschrijving wijzigen");

        jLabel1.setText("Inschrijvings id");

        jLabel2.setText("geselecteerde toernooi: ");

        toernooiField.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                toernooiFieldActionPerformed(evt);
            }
        });

        jLabel4.setText("geselecteerde speler ");

        spelerBetaaldCheckbox.setText(" speler heeft betaald");
        spelerBetaaldCheckbox.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                spelerBetaaldCheckboxActionPerformed(evt);
            }
        });

        confirmButton.setText("Gegevens wijzigen");
        confirmButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                confirmButtonActionPerformed(evt);
            }
        });

        searchButton.setText("zoeken");
        searchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                searchButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabel1)
                            .addGap(53, 53, 53)
                            .addComponent(searchField, javax.swing.GroupLayout.PREFERRED_SIZE, 162, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(searchButton))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(jLabel2)
                                .addComponent(jLabel4))
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addComponent(spelerField, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 235, Short.MAX_VALUE)
                                .addComponent(toernooiField))))
                    .addComponent(spelerBetaaldCheckbox)
                    .addComponent(confirmButton, javax.swing.GroupLayout.DEFAULT_SIZE, 415, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(searchField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(searchButton))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(toernooiField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(spelerField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addGap(18, 18, 18)
                .addComponent(spelerBetaaldCheckbox)
                .addGap(18, 18, 18)
                .addComponent(confirmButton)
                .addContainerGap(41, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

private void toernooiFieldActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_toernooiFieldActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_toernooiFieldActionPerformed

private void searchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_searchButtonActionPerformed
// TODO add your handling code here:
    try {
        int inschrijvingID = Integer.parseInt(searchField.getText());
        toernooiWijzigen = ToernooiInschrijving.getInschrijving(inschrijvingID);
        Toernooi toernooi = toernooiWijzigen.getToernooi();
        String toernooiValue = String.valueOf(toernooi.getToernooiid());
        Speler speler = toernooiWijzigen.getSpeler();
        String spelerValue = String.valueOf(speler.getSpelerid());
        toernooiField.setText(toernooiValue);
        spelerField.setText(spelerValue);
        spelerBetaaldCheckbox.setSelected(toernooiWijzigen.getBetaald());
       
    } catch (NumberFormatException e) {
        JOptionPane.showMessageDialog(null, "Toernooiid moet geheel nummer zijn", "Fout", JOptionPane.ERROR_MESSAGE);
        toernooiField.setText("Geen");
        spelerField.setText("Geen");
    }
}//GEN-LAST:event_searchButtonActionPerformed

private void confirmButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_confirmButtonActionPerformed
// TODO add your handling code here:

    
            ToernooiInschrijving inschrijving = new ToernooiInschrijving();
            String toernooiIDString = toernooiField.getText();
            int toernooiID = Integer.parseInt(toernooiIDString);
            String speleridd = spelerField.getText();
            int spelerID = Integer.parseInt(speleridd);


            
                inschrijving.setInschrijvingID(toernooiWijzigen.getInschrijvingID());
                inschrijving.setToernooi(Toernooi.getToernooi(toernooiID));
                inschrijving.setSpeler(Speler.getSpeler(spelerID));
                inschrijving.setBetaald(spelerBetaaldCheckbox.isSelected());
                System.out.println(spelerBetaaldCheckbox.isSelected());





                if (inschrijving.update() == true) {
                    JOptionPane.showMessageDialog(null, "De inschrijving is succesvol gewijzigd.");
                } 
}//GEN-LAST:event_confirmButtonActionPerformed

private void spelerBetaaldCheckboxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_spelerBetaaldCheckboxActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_spelerBetaaldCheckboxActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(ToernooiSpelerWijzigen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(ToernooiSpelerWijzigen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(ToernooiSpelerWijzigen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(ToernooiSpelerWijzigen.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new ToernooiSpelerWijzigen().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton confirmButton;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JButton searchButton;
    private javax.swing.JTextField searchField;
    private javax.swing.JCheckBox spelerBetaaldCheckbox;
    private javax.swing.JTextField spelerField;
    private javax.swing.JTextField toernooiField;
    // End of variables declaration//GEN-END:variables
}
